import ServiceBase from '../base';
import {FileUploadHeader, UPLOAD_REQUEST_TIMEOUT} from '../context/context-base';
import * as proxy from '../proxy';

const GET_BUCKTES = '/buckets';

class StorageService extends ServiceBase {
    getBucket = () => {
        let promise = super.get({
            url: GET_BUCKTES,
        });
        return proxy.httpResultProxy(promise);
    };
    postBucket = (data) => {
        let promise = super.post({
            url: GET_BUCKTES,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    getObjects = (data) => {
        // bimbox-model-link
        let promise = super.get({
            url: GET_BUCKTES + `/${data}/objects`,
            params: data,
        });
        return proxy.httpResultProxy(promise);
    };
    // postObjects = (data) => {
    //   let promise = super.post(GET_BUCKTES + `/${data.bucketKey}/objects/${data.urn}`, JSON.stringify(data.data), '', {'Content-Type': 'application/octet-stream');
    //   return proxy.httpResultProxy(promise);
    // };
    postObjects = (data) => {
        let promise = super.post({
            url: data.uploadActionUrl,
            data: JSON.stringify(data.data),
            headers: {
                'Content-Type': 'application/octet-stream',
                [FileUploadHeader]: data.signature,
            },
            timeout: UPLOAD_REQUEST_TIMEOUT,
        });
        return proxy.httpResultProxy(promise);
    };
    getObjectsData = (data) => {
        // bimbox-model-link
        let promise = super.get({
            url: GET_BUCKTES + `/${data.bucketKey}/objects/${data.id}`,
        });
        return proxy.httpResultProxy(promise);
    };
    getPublicObjectsData = (data) => {
        // bimbox-model-link
        let promise = super.getWithoutToken({
            url: GET_BUCKTES + `/${data.bucketKey}/objects/${data.id}?client_id=${data.clientId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // getThumbnailSignature = (data) => {
    //   let promise = super.post(`/signedObjects${GET_BUCKTES}/${data.bucketKey}/objects/${data.objectKey}`, data.data)
    //   return proxy.httpResultProxy(promise)
    // }
    getThumbnailSignature = (data) => {
        let promise = super.post({
            url: `/signedObjects`,
            data,
        });
        return proxy.httpResultProxy(promise);
    };
    detectFileExists = (data) => {
        let promise = super.post({
            url: `/file/detectFileExists`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {StorageService};
